/*
 * Copyright (c) 2022 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "spatial_location_info.h"

#include "string_ex.h"
#include "spatial_awareness_common.h"

namespace OHOS {
namespace Msdp {
bool DirectionResponse::ReadFromParcel(Parcel &parcel)
{
    directionType = static_cast<DirectionType>(parcel.ReadInt32());
    return true;
}

DirectionResponse *DirectionResponse::Unmarshalling(Parcel &parcel)
{
    DirectionResponse *directionRes = new (std::nothrow) DirectionResponse();
    if (directionRes && !directionRes->ReadFromParcel(parcel)) {
        SPATIAL_LOGI(MODULE_INNERKIT, "DirectionResponse::Unmarshalling ReadFromParcel failed");
        delete directionRes;
        directionRes = nullptr;
    }
    return directionRes;
}

bool DirectionResponse::Marshalling(Parcel &parcel) const
{
    return (parcel.WriteInt32(static_cast<int32_t>(directionType)));
}

bool DistanceResponse::ReadFromParcel(Parcel &parcel)
{
    distance = parcel.ReadDouble();
    return true;
}

DistanceResponse *DistanceResponse::Unmarshalling(Parcel &parcel)
{
    DistanceResponse *distanceRes = new (std::nothrow) DistanceResponse();
    if (distanceRes && !distanceRes->ReadFromParcel(parcel)) {
        SPATIAL_LOGI(MODULE_INNERKIT, "DistanceResponse::Unmarshalling ReadFromParcel failed");
        delete distanceRes;
        distanceRes = nullptr;
    }
    return distanceRes;
}

bool DistanceResponse::Marshalling(Parcel &parcel) const
{
    return (parcel.WriteDouble(distance));
}

bool AngleResponse::ReadFromParcel(Parcel &parcel)
{
    angle = parcel.ReadDouble();
    return true;
}

AngleResponse *AngleResponse::Unmarshalling(Parcel &parcel)
{
    AngleResponse *angleRes = new (std::nothrow) AngleResponse();
    if (angleRes && !angleRes->ReadFromParcel(parcel)) {
        SPATIAL_LOGI(MODULE_INNERKIT, "AngleResponse::Unmarshalling ReadFromParcel failed");
        delete angleRes;
        angleRes = nullptr;
    }
    return angleRes;
}

bool AngleResponse::Marshalling(Parcel &parcel) const
{
    return (parcel.WriteDouble(angle));
}


bool InnerOuterResponse::ReadFromParcel(Parcel &parcel)
{
    innerOuterType = static_cast<InnerOuterType>(parcel.ReadInt32());
    return true;
}

InnerOuterResponse *InnerOuterResponse::Unmarshalling(Parcel &parcel)
{
    InnerOuterResponse *ioRes = new (std::nothrow) InnerOuterResponse();
    if (ioRes && !ioRes->ReadFromParcel(parcel)) {
        SPATIAL_LOGI(MODULE_INNERKIT, "InnerOuterResponse::Unmarshalling ReadFromParcel failed");
        delete ioRes;
        ioRes = nullptr;
    }
    return ioRes;
}

bool InnerOuterResponse::Marshalling(Parcel &parcel) const
{
    return (parcel.WriteInt32(static_cast<int32_t>(innerOuterType)));
}

bool ExistResponse::ReadFromParcel(Parcel &parcel)
{
    existType = static_cast<ExistType>(parcel.ReadInt32());
    return true;
}

ExistResponse *ExistResponse::Unmarshalling(Parcel &parcel)
{
    ExistResponse *existRes = new (std::nothrow) ExistResponse();
    if (existRes && !existRes->ReadFromParcel(parcel)) {
        SPATIAL_LOGI(MODULE_INNERKIT, "ExistResponse::Unmarshalling ReadFromParcel failed");
        delete existRes;
        existRes = nullptr;
    }
    return existRes;
}

bool ExistResponse::Marshalling(Parcel &parcel) const
{
    return (parcel.WriteInt32(static_cast<int32_t>(existType)));
}
}  // namespace Msdp
}  // namespace OHOS
